package task3

case class UserInfo(name: String, location:String, startTime: Int, duration: Int)

object LocationAndDuration {
  def main(args: Array[String]): Unit = {
    val userInfoList = List(
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserA", "LocationA", 9, 60),
      UserInfo("UserB", "LocationB", 10, 60),
      UserInfo("UserB", "LocationB", 11, 80)
    )
    val userMap: Map[String, List[UserInfo]] = userInfoList.groupBy(t => t.name + "|" + t.location)
//    println(userMap.toString())
    val orderedMap: Map[String, List[UserInfo]] = userMap.mapValues(t => t.sortBy(_.startTime))
//    println(orderedMap.toString())
    val resultMap = orderedMap.mapValues(t => {
      val firstTime = t(0).startTime
      val dur = t.map(_.duration).sum
      (firstTime, dur)
    })
//    println(resultMap.toString())
    resultMap.foreach(x =>{
      println(x._1.replace("|", ",") + "," + x._2._1 + "," + x._2._2)
    }
    )
  }
}
